home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Moscow ML 1.42 / examples / cgi / cgiex1.sml next >
Encoding:
Text File  |  1997-08-18  |  1.2 KB  |  40 lines  |  [TEXT/R*ch]

  1. (* File mosml/examples/cgi/cgiex1.sml 
  2.  
  3.    Example CGI program, which may be invoked by the webserver to
  4.    handle requests transmitted from the example HTML FORM in file
  5.    htmlform.html.  See file README1 for instructions.
  6.  
  7.  *)
  8.  
  9. open Mosmlcgi;
  10.  
  11. fun prtint i = print (Int.toString i)
  12. fun prtline sus = (print (Substring.string sus); print "\n")
  13. fun lines s = Substring.fields (fn c => c = #"\n") (Substring.all s)
  14.  
  15. fun processfile filedata =
  16.     (case valOf (cgi_field_string "action") of
  17.      "count characters" => 
  18.          (print "Text contains "; 
  19.           prtint (size filedata); 
  20.           print " characters\n")
  21.        | "count lines" => 
  22.          (print "Text contains "; 
  23.           prtint (length (lines filedata)); 
  24.           print " lines\n")
  25.        | "sort" => 
  26.          (print "Sorted text:<P>\n<PRE>";
  27.           app prtline (Listsort.sort Substring.compare (lines filedata));
  28.           print "</PRE>\n")
  29.        | _ => 
  30.          print "Unknown action\n")
  31.     handle Option => print "No action\n"
  32.  
  33. val _ = 
  34.     (print "Content-type: text/html\n\n";
  35.      print "<HTML><BODY>";
  36.      (case cgi_field_string "texttoprocess" of
  37.       SOME data => processfile data
  38.     | NONE      => print "No text to process\n");
  39.      print "</BODY></HTML>")
  40.